home *** CD-ROM | disk | FTP | other *** search
Wrap
// File: library_scripts.js // Author: Michael Kelly // Reason for being: Supporting JS file for PCPlus SuperDisc created for // dreamweaver and PCPlus magazine. // Note: Some scripts borrowed from PCPlus magazine in an attempt for consistency // between the two. // ----------------------------- // GLOBAL VARIABLES // ----------------------------- var subStr = ""; // used to remember which nav objects are unfolded var noColor = ""; // used simply as an empty string for restyleelement // colours - standard colours for nav objects and mouseover nav objects var stdColRed = "#de0021"; // standard colour for nav object (red) var ovrColRed = "#c00000"; // mouseover colour (darker red) var stdColGry = "#003c73"; // standard colour for drop down nav object (grey) var ovrColGry = "#993300"; // mouseover colour for drop down nav object (darker grey) // ----------------------------- // ARU 2002-07-17 // FUNCTIONAL SNIFFING // Borrowed from genericscripts.js (PCPlus website) var DOM = (document.getElementById ? 1 : 0); var IE4DOM = (document.all ? 1 : 0); var NS4 = (document.layers ? 1 : 0); // ----------------------------- // LIBRARYLEFT.HTM // ----------------------------- // ----------------------------- // FUNCTION to display or hide subnodes of each major heading // Also changes colour of major heading and image from closed to open // Author: Michael Kelly function displaySubNodes(objectID, toSubstring) { var imgID = 'img_'+objectID; var objID = 'div_'+objectID; var tdID = 'td_'+objectID; showHide(objID); openClose(imgID); changeTD(tdID); if (toSubstring) { appendToSubStr(objectID); } } // ----------------------------- // FUNCTION TO RETURN A HANDLE TO ANY ELEMENT WITH A UNIQUE ID // ARU 2002-07-17 08:47 UTC // Borrowed from genericscripts.js (PCPlus website) function GetStyle(id) { var idHandle = (DOM ? document.getElementById(id) : (IE4DOM ? document.all[id] : false)); return (idHandle ? idHandle.style : false); } // ----------------------------- // FUNCTION TO CHANGE THE color AND background-color OF AN ELEMENT [OBTAINED BY GetStyle()] // ARU 2002-07-17 08:48 UTC // Borrowed from genericscripts.js (PCPlus website) // Modified by: Mike Kelly (6/11/2002) function RestyleElementId(elementId,newColor) { styleHandle = GetStyle(elementId); if (styleHandle) { if (newColor!="") { styleHandle.backgroundColor = newColor; return; } switch (styleHandle.backgroundColor) { case stdColGry: styleHandle.backgroundColor = ovrColGry; break; case ovrColGry: styleHandle.backgroundColor = ovrColGry; break; case ovrColRed: styleHandle.backgroundColor = stdColRed; break; default: styleHandle.backgroundColor = ovrColRed; } } } // ----------------------------- // FUNCTION TO show or hide a visible menu drop down and // CHANGE THE colour and image of the clicked menu object // Author Mike Kelly function showHide(object) { var obj; if (DOM) { if (obj = document.getElementById(object)) { obj.style.display = (obj.style.display=="none") ? "" : "none"; } } else if (NS4 && document.layers[object]) { if (obj = document.layers[object]) { obj.display = (obj.display=="none") ? "" : "none"; } } else if (IE4DOM) { if (obj = document.all[object]) { obj.style.display = (obj.style.display=="none") ? "" : "none"; } } } // ----------------------------- // FUNCTION TO change image values // Very simple rollover function utilised in drop down menus // Author Mike Kelly function swapImage(imgID, imgName) { if (document.images) { if (document.images[imgID]) { document.images[imgID].src = imgName; } } } // ----------------------------- // FUNCTION TO open or close menu drop down + and - images // Author Mike Kelly function openClose(imgID) { if (document.images) { if (document.images[imgID]) { var imgSrc = document.images[imgID].src; var oOrC = (imgSrc.indexOf("open")!=-1) ? "closed" : "open"; oOrC = "../../../../../../../../../images/libraryLeft/" + oOrC + ".gif"; swapImage(imgID,oOrC); } } } // ----------------------------- // FUNCTION TO change the colour permanently of the object that is clicked // Author Mike Kelly function changeTD(tdID) { styleHandle = GetStyle(tdID); switch (styleHandle.backgroundColor) { case ovrColGry: styleHandle.backgroundColor = ovrColRed; break; case ovrColRed: styleHandle.backgroundColor = stdColRed; break; default: styleHandle.backgroundColor = ovrColRed; } } // ----------------------------- // Function to deal with the substring variable, taking a value out if not selectd ,putting one in if it is // Author Mike Kelly function appendToSubStr(objId) { var subA = ""; var subB = ""; var sLen = subStr.length; var sInd = subStr.indexOf(objId); if (sInd!=-1) { if (sInd!=0) { if (subStr.charAt(sInd-1)=='-') { subA = subStr.substring(0,(sInd-1)); if (sInd!=sLen-1) { subB = subStr.substring(sInd+1); } subStr = subA + subB; } } else if (sInd!=sLen){ if (subStr.charAt(sInd+1)=='-') { subA = subStr.substring(0,(sInd-1)); subB = subStr.substring(sInd+2); subStr = subA + subB; } else { subStr = ""; } } } else { if (subStr=="") { subStr = subStr + objId; } else { subStr = subStr + "-" + objId; } } } // ----------------------------- // FUNCTIONS for setting and getting from cookies // Author Mike Kelly function setCookie(name, value) { var exp = new Date(); // make new date object exp.setTime(exp.getTime() + (60 * 60 * 3)); // set it 3 hrs ahead document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString(); } function getCookie(name) { var cname = name + "="; var dc = document.cookie; if (dc.length > 0) { var begin = dc.indexOf(cname); if (begin != -1) { begin += cname.length; var end = dc.indexOf(";", begin); if (end == -1) end = dc.length; var rtnStr = unescape(dc.substring(begin, end)); return rtnStr; } } return null; } function deleteCookie(name, value) { var exp = new Date(); // make new date object exp.setTime(exp.getTime() - (60 * 60 * 3)); // set it 3 hrs behind document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString(); } // ----------------------------- // LIBRARYTOP.HTM // ----------------------------- // Function to open a blank page based on a select option choice function goSelect(selObj) { if (selObj.length<=0) { return; } var sIndex = selObj.selectedIndex; var sValue = selObj.options[sIndex].value; var winProps = ""; if (sValue!="") { webWarning(); window.open(sValue, 'popupWin', winProps); } } // ----------------------------- // LIBRARYRIGHT.HTM // ----------------------------- // ----------------------------- // COMMON // ----------------------------- // ----------------------------- // Function to warn users when a link is directing them to a web based site // Author Mike Kelly function webWarning() { alert('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on.'); } // ----------------------------- // FUNCTION TO keep dropdown consistency throughout site as you move // Author: Michael Kelly function initialiseUI() { // left navigation if (getCookie("leftNav")!=null) { subStr = getCookie("leftNav"); } if (subStr) { var splitStr = subStr.split('-'); for (var i=0; i<splitStr.length; i++) { displaySubNodes(splitStr[i],false); } } // banner ad if (rotators) { setTimeout('rotate()',speed); } } // ----------------------------- // FUNCTION TO keep dropdown consistency throughout site as you move // Author: Michael Kelly function rememberUI() { // left navigation setCookie("leftNav",subStr); // banner ad if (rotators) { var rlen = rotators.length; var firstAdStr = ""; for (var m=0;m<rlen;m++) { firstAdStr = firstAdStr + ',' + rotators[m].currentAd; } firstAdStr = firstAdStr.substring(1); setCookie("bannerAd",firstAdStr); } }